#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->pbt_target->setIcon(QIcon(":/image/target.png")); //设置图片
    ui->pbt_target->setIconSize(QSize(85,85)); //设置图片大小

    ui->pbt_u->setIcon(QIcon(":/image/up.png"));
    ui->pbt_u->setIconSize(QSize(30,30));
    ui->pbt_u->setAutoRepeat(true); //设置点击不释放可连续触发
    ui->pbt_u->setShortcut(Qt::Key_W); //设置快捷键

    ui->pbt_d->setIcon(QIcon(":/image/down.png"));
    ui->pbt_d->setIconSize(QSize(30,30));
    ui->pbt_d->setAutoRepeat(true);
    ui->pbt_d->setShortcut(Qt::Key_S);

    ui->pbt_l->setIcon(QIcon(":/image/left.png"));
    ui->pbt_l->setIconSize(QSize(30,30));
    ui->pbt_l->setAutoRepeat(true);
    ui->pbt_l->setShortcut(Qt::Key_A);

    ui->pbt_r->setIcon(QIcon(":/image/right.png"));
    ui->pbt_r->setIconSize(QSize(30,30));
    ui->pbt_r->setAutoRepeat(true);
    ui->pbt_r->setShortcut(Qt::Key_D);

    ui->pbt_lu->setIcon(QIcon(":/image/lu.png"));
    ui->pbt_lu->setIconSize(QSize(30,30));
    ui->pbt_lu->setAutoRepeat(true);
    ui->pbt_lu->setShortcut(Qt::Key_A + Qt::Key_W);

    ui->pbt_ld->setIcon(QIcon(":/image/ld.png"));
    ui->pbt_ld->setIconSize(QSize(30,30));
    ui->pbt_ld->setAutoRepeat(true);
    ui->pbt_ld->setShortcut(Qt::Key_A + Qt::Key_S);

    ui->pbt_ru->setIcon(QIcon(":/image/ru.png"));
    ui->pbt_ru->setIconSize(QSize(30,30));
    ui->pbt_ru->setAutoRepeat(true);
    ui->pbt_ru->setShortcut(Qt::Key_D + Qt::Key_W);

    ui->pbt_rd->setIcon(QIcon(":/image/rd.png"));
    ui->pbt_rd->setIconSize(QSize(30,30));
    ui->pbt_rd->setAutoRepeat(true);
    ui->pbt_ru->setShortcut(Qt::Key_D + Qt::Key_S);

}

Widget::~Widget()
{
    delete ui;
}

//向上移动
void Widget::on_pbt_u_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
}

//向左移动
void Widget::on_pbt_l_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
}

//向右移动
void Widget::on_pbt_r_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
}

//向下移动
void Widget::on_pbt_d_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
}

//左上
void Widget::on_pbt_lu_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()-5,rect.y()-5,rect.width(),rect.height());
}

//右上
void Widget::on_pbt_ru_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()+5,rect.y()-5,rect.width(),rect.height());
}

//左下
void Widget::on_pbt_ld_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()-5,rect.y()+5,rect.width(),rect.height());
}

//右下
void Widget::on_pbt_rd_clicked()
{
    QRect rect = ui->pbt_target->geometry();
    ui->pbt_target->setGeometry(rect.x()+5,rect.y()+5,rect.width(),rect.height());
}
